package razor.blade;

import javafx.scene.*;
import javafx.beans.property.*;
import javafx.beans.value.*;
import javafx.geometry.*;
import tee.binding.*;

public class Lasso {
    private Numeric width;
    private Numeric height;
    private Group root;
    public Node node() {
        return root;
    }
    public Lasso content(Node n) {
        root.getChildren().clear();
        root.getChildren().add(n);
	//System.out.println(n.getBoundsInLocal());
        return this;
    }
    public Lasso width(double it) {
	width.value(it);
	return this;
    }
    public Lasso width(int it) {
	width.value(it);
	return this;
    }
    public Numeric width() {
	return width;
    }
    public Lasso width(It<Double> it) {
	width.bind(it);
	return this;
    }
    public Lasso height(double it) {
	height.value(it);
	return this;
    }
    public Lasso height(int it) {
	height.value(it);
	return this;
    }
    public Numeric height() {
	return height;
    }
    public Lasso height(It<Double> it) {
	height.bind(it);
	return this;
    }
    
    public Lasso() {
        width = new Numeric().value(0);
        height = new Numeric().value(0);
        root = new Group();
        root.boundsInParentProperty().addListener(new ChangeListener<Bounds>() {
            public void changed(ObservableValue<? extends Bounds> observable, Bounds oldValue, Bounds newValue) {
                width.value(root.getBoundsInLocal().getWidth());
                height.value(root.getBoundsInLocal().getHeight());
                //System.out.println(": "+height.value()+"x"+height.value()+root.getBoundsInLocal());
            }
        });
    }
}
